package com.design.working.controller;

import com.design.working.config.BaseServlet;
import com.design.working.dto.*;
import com.design.working.service.AdminService;
import com.design.working.service.impl.AdminServiceImpl;
import com.google.gson.Gson;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.math.BigDecimal;

/**
 * 管理员端控制器
 *
 * @author gavin
 * @date 2022/5/18 09:56
 */
@WebServlet(name = "AdminController",
        urlPatterns = {"/admin/*"})
public class AdminController extends BaseServlet {

    /**
     * 没有参数, "0"
     */
    private static final String NO_PARAM = "0";

    private final AdminService adminService = new AdminServiceImpl();

    /**
     * （事务审批）学生岗位申请 - 查找未处理的学生工作申请记录
     */
    public void selectStudentWorkApplication(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectStudentWorkApplication(pageControlDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （事务审批）学生岗位申请 - 插入管理员对学生申请记录的审批内容
     */
    public void handleStudentWorkApplication(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            HttpSession session = request.getSession();

            Integer uid = (Integer) session.getAttribute("uid");

            AdminHandleStudentApplicationDTO adminHandleStudentApplicationDTO = new AdminHandleStudentApplicationDTO();
            adminHandleStudentApplicationDTO.setId(Integer.valueOf(request.getParameter("id")));
            adminHandleStudentApplicationDTO.setWorkTime(request.getParameter("workTime"));
            adminHandleStudentApplicationDTO.setAdvice(request.getParameter("advice"));
            adminHandleStudentApplicationDTO.setOperation(Integer.valueOf(request.getParameter("operation")));
            response.getWriter().print(adminService.insertStudentApplicationHanding(uid, adminHandleStudentApplicationDTO));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （事务审批）学生岗位申请 - 查找申请表中学生申请工作填写的个人信息
     */
    public void selectStudentDetail(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取学生信息id
            Integer smtId = Integer.valueOf(request.getParameter("smtId"));

            response.getWriter().print(gson.toJson(adminService.selectStudentApplicationDetail(smtId)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （事务审批）学生岗位申请 - 查找辅导员和用工部门对学生申请表的意见
     */
    public void selectStudentPreAdvice(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取学生申请记录id
            Integer swaId = Integer.valueOf(request.getParameter("swaId"));
            response.getWriter().print(gson.toJson(adminService.selectStudentPreAdvice(swaId)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （事务审批）学生岗位变动 - 查看学生岗位变动申请
     */
    public void selectStudentWorkMotion(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectStudentWorkMotion(pageControlDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （事务审批）学生岗位变动 - 插入管理员对学生岗位变更申请的审批内容
     */
    public void handleStudentWorkMotion(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            HttpSession session = request.getSession();

            // 管理员uid
            Integer uid = (Integer) session.getAttribute("uid");

            AdminHandleStudentMotionDTO adminHandleStudentMotionDTO = new AdminHandleStudentMotionDTO();
            adminHandleStudentMotionDTO.setId(Integer.valueOf(request.getParameter("id")));
            adminHandleStudentMotionDTO.setAdvice(request.getParameter("advice"));
            adminHandleStudentMotionDTO.setOperation(Integer.valueOf(request.getParameter("operation")));

            response.getWriter().print(adminService.insertStudentMotionHanding(uid, adminHandleStudentMotionDTO));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （事务审批）学生岗位变动 - 查找用工部门对学生岗位变动的意见
     */
    public void selectStudentPreAdviceFromDept(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取学生信息id
            Integer id = Integer.valueOf(request.getParameter("id"));
            response.getWriter().print(gson.toJson(adminService.selectDeptPreAdvice(id)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void selectAllWorking(HttpServletRequest request, HttpServletResponse response) {
        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));


            response.getWriter().print(gson.toJson(adminService.selectAllWorking(pageControlDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （在岗学生管理）变更岗位 - 查找正在工作的学生和岗位信息
     */
    public void selectAllWorkingByName(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");
            SearchDTO searchDTO = new SearchDTO();
            searchDTO.setId(uid);
            searchDTO.setName(studentName);

            response.getWriter().print(gson.toJson(adminService.selectAllWorkingByName(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * （在岗学生管理）变更岗位 - 强制将在岗学生下岗
     */
    public void forceResignStudent(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            HttpSession session = request.getSession();
            Integer adminId = (Integer) session.getAttribute("uid");
            Integer id = Integer.valueOf(request.getParameter("id"));
            response.getWriter().print(adminService.forceResignStudent(id, adminId));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void selectWorkDistributionRecord(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");
            SearchDTO searchDTO = new SearchDTO();
            searchDTO.setId(uid);
            searchDTO.setName(studentName);

            response.getWriter().print(gson.toJson(adminService.selectWorkDistributionRecord(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询在岗学生考勤记录
     */
    public void selectStudentAttendance(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");
            // 获取查询时间范围
            String beginDate = request.getParameter("beginDate");
            String endDate = request.getParameter("endDate");

            SearchDTO searchDTO = new SearchDTO(uid, studentName, beginDate, endDate);

            response.getWriter().print(gson.toJson(adminService.selectStudentAttendance(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询全部学生考勤记录
     */
    public void selectAllAttendance(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");
            // 获取查询时间范围
            String beginDate = request.getParameter("beginDate");
            String endDate = request.getParameter("endDate");

            SearchDTO searchDTO = new SearchDTO(uid, studentName, beginDate, endDate);

            response.getWriter().print(gson.toJson(adminService.selectAllAttendance(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询学生相关信息
     */
    public void selectStudent(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");

            SearchDTO searchDTO = new SearchDTO();
            searchDTO.setId(uid);
            searchDTO.setName(studentName);

            response.getWriter().print(gson.toJson(adminService.selectStudent(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询学生详细信息
     */
    public void selectStudentMsg(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取学生学号
            Integer uid = Integer.valueOf(request.getParameter("uid"));

            response.getWriter().print(gson.toJson(adminService.selectStudentMsg(uid)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询学生申请岗位的信息
     */
    public void selectStudentApplicationRecord(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");

            SearchDTO searchDTO = new SearchDTO();
            searchDTO.setId(uid);
            searchDTO.setName(studentName);

            response.getWriter().print(gson.toJson(adminService.selectStudentApplicationRecord(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询学生岗位申请的记录
     */
    public void selectStudentApplicationExamination(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            Integer swaId = Integer.valueOf(request.getParameter("swaId"));
            response.getWriter().print(gson.toJson(adminService.selectStudentApplicationExamination(swaId)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 岗位工资查询
     */
    public void selectJobSalary(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectJobSalary(pageControlDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 修改岗位工资
     */
    public void updateJobSalaryById(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            UpdateJobSalaryDTO updateJobSalaryDTO = new UpdateJobSalaryDTO();

            updateJobSalaryDTO.setId(Integer.valueOf(request.getParameter("id")));
            int tempSalary = Integer.parseInt(request.getParameter("newSalary"));
            updateJobSalaryDTO.setNewSalary(new BigDecimal(tempSalary));

            response.getWriter().print(adminService.updateJobSalaryById(updateJobSalaryDTO));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询学生工资
     */
    public void selectStudentSalary(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectStudentSalary(pageControlDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过姓名查询学生工资
     */
    public void selectStudentSalaryByName(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            // 获取uid和studentName
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");
            String studentName = request.getParameter("studentName");
            // 获取查询时间范围
            String beginDate = request.getParameter("beginDate");
            String endDate = request.getParameter("endDate");

            SearchDTO searchDTO = new SearchDTO(uid, studentName, beginDate, endDate);

            response.getWriter().print(gson.toJson(adminService.selectStudentSalaryByName(pageControlDTO, searchDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询所有待审批的部门申请岗位
     */
    public void selectDeptJobApplication(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectDeptJobApplication(pageControlDTO)));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询部门申请岗位的详细信息
     */
    public void selectDeptJobApplicationDetail(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            Integer id = Integer.valueOf(request.getParameter("id"));

            response.getWriter().print(gson.toJson(adminService.selectDeptJobApplicationDetail(id)));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 处理对部门岗位的申请
     */
    public void handleDeptJobApplication(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            // 获取前端数据
            HandleDeptJobApplicationDTO handleDeptJobApplicationDTO = new HandleDeptJobApplicationDTO();
            handleDeptJobApplicationDTO.setId(Integer.valueOf(request.getParameter("id")));
            handleDeptJobApplicationDTO.setAdvice(request.getParameter("advice"));
            handleDeptJobApplicationDTO.setSalary(new BigDecimal(request.getParameter("salary")));
            handleDeptJobApplicationDTO.setOperation(Integer.valueOf(request.getParameter("operation")));

            // 获取管理员uid
            HttpSession session = request.getSession();
            handleDeptJobApplicationDTO.setUid((Integer) session.getAttribute("uid"));

            // 执行操作
            response.getWriter().print(adminService.handleDeptJobApplication(handleDeptJobApplicationDTO));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询部门岗位变动信息
     */
    public void selectDeptJobMotion(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();
            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectDeptJobMotion(pageControlDTO)));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 处理部门岗位变更
     */
    public void handleDeptJobWorkMotion(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");
            HttpSession session = request.getSession();

            Gson gson = new Gson();

            AdminHandleDeptJobWorkMotionDTO adminHandleDeptJobWorkMotionDTO = new AdminHandleDeptJobWorkMotionDTO();

            adminHandleDeptJobWorkMotionDTO.setId(Integer.valueOf(request.getParameter("id")));
            adminHandleDeptJobWorkMotionDTO.setType(Integer.valueOf(request.getParameter("type")));
            adminHandleDeptJobWorkMotionDTO.setAdvice(request.getParameter("advice"));
            adminHandleDeptJobWorkMotionDTO.setUid((Integer) session.getAttribute("uid"));
            adminHandleDeptJobWorkMotionDTO.setOperation(Integer.valueOf(request.getParameter("operation")));

            response.getWriter().print(gson.toJson(adminService.insertDeptJobWorkMotionHandling(adminHandleDeptJobWorkMotionDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询所有部门岗位申请记录
     */
    public void selectDeptJobApplicationRecord(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectDeptJobApplicationRecord(pageControlDTO)));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过关键字查询部门岗位申请记录
     */
    public void selectDirectDeptJobApplicationRecord(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();

            SearchDeptJobApplicationDTO searchDeptJobApplicationDTO = new SearchDeptJobApplicationDTO();
            searchDeptJobApplicationDTO.setDeptName(request.getParameter("deptName"));
            // 空值转换
            String startYear = "".equals(request.getParameter("startYear")) ? NO_PARAM : request.getParameter("startYear");
            searchDeptJobApplicationDTO.setStartYear(Integer.valueOf(startYear));
            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            response.getWriter().print(gson.toJson(adminService.selectDirectDeptJobApplicationRecord(pageControlDTO, searchDeptJobApplicationDTO)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查询岗位申请记录的审批详情
     */
    public void selectDeptJobApplicationExamination(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Integer id = Integer.valueOf(request.getParameter("id"));
            Gson gson = new Gson();

            response.getWriter().print(gson.toJson(adminService.selectDeptJobApplicationExamination(id)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查看所有用工评价
     */
    public void selectWorkEvaluation(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            Gson gson = new Gson();

            response.getWriter().print(gson.toJson(adminService.selectWorkEvaluation(pageControlDTO)));


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 通过关键词查看部门用工评价
     */
    public void selectWorkEvaluationByName(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            // 获取分页参数
            PageControlDTO pageControlDTO = new PageControlDTO();
            pageControlDTO.setPage(Integer.valueOf(request.getParameter("page")));
            pageControlDTO.setLimit(Integer.valueOf(request.getParameter("limit")));

            SearchWorkEvaluationDTO searchWorkEvaluationDTO = new SearchWorkEvaluationDTO();
            // 空值转换
            String uid = "".equals(request.getParameter("uid")) ? NO_PARAM : request.getParameter("uid");

            searchWorkEvaluationDTO.setUid(Integer.valueOf(uid));
            searchWorkEvaluationDTO.setName(request.getParameter("studentName"));
            searchWorkEvaluationDTO.setDeptName(request.getParameter("deptName"));
            Gson gson = new Gson();

            response.getWriter().print(gson.toJson(adminService.selectWorkEvaluationByName(pageControlDTO, searchWorkEvaluationDTO)));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查看部门用工评价的详细评价
     */
    public void selectWorkEvaluationDetailById(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Gson gson = new Gson();
            Integer id = Integer.valueOf(request.getParameter("id"));

            response.getWriter().print(gson.toJson(adminService.selectWorkEvaluationDetailById(id)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 手动对单个学生结岗
     */
    public void finishStudentWorkById(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            Integer id = Integer.valueOf(request.getParameter("id"));

            response.getWriter().print(adminService.finishStudentWorkById(id));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 查看工资是否被统计
     */
    public void selectSalaryStatusByDate(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            String date = request.getParameter("date");

            response.getWriter().print(adminService.selectSalaryStatusByDate(date));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 统计某月工资情况
     */
    public void countSalaryByDate(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            String date = request.getParameter("date");

            response.getWriter().print(adminService.countSalaryByDate(date));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 操作月发放上月工资
     */
    public void sendSalaryByDate(HttpServletRequest request, HttpServletResponse response) {

        try {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/javascript; charset=UTF-8");

            String date = request.getParameter("date");

            response.getWriter().print(adminService.sendSalaryByDate(date));

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}